// pages/home4/home.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        banner: ['https://pimg.ec51.com/1522376146099'],
        imgheights: [],
        scrollWidth: 0,
        currentNavtab: 0,//当前第几个swiper 
        recommended: [
            {
                image: 'http://oj1itelvn.bkt.clouddn.com/cs-banner3.jpg',
                bookName: '风格练习',
                author: '雷蒙啥啥啥啊数据库丁俊晖放辣椒卡萨丁恢复健康撒地方啊数据库的恢复卡萨丁回复可见阿斯顿飞'
            },
            {
                image: 'https://img.zhxcxmall.com/book/book-test.png',
                bookName: '风格练习',
                author: '雷蒙啥啥啥'
            },
            {
                image: 'https://img.zhxcxmall.com/book/book-test2.png',
                bookName: '风格练习',
                author: '【法】雷蒙啥啥啥'
            },
            {
                image: 'https://img.zhxcxmall.com/book/book-test2.png',
                bookName: '风格练习',
                author: '【法】雷蒙啥啥啥'
            },
            {
                image: 'https://img.zhxcxmall.com/book/book-test2.png',
                bookName: '风格练习',
                author: '【法】雷蒙啥啥啥'
            },
            {
                image: 'https://img.zhxcxmall.com/book/book-test2.png',
                bookName: '风格练习',
                author: '【法】雷蒙啥啥啥'
            },
            {
                image: 'https://img.zhxcxmall.com/book/book-test2.png',
                bookName: '风格练习',
                author: '【法】雷蒙啥啥啥'
            },
            {
                image: 'https://img.zhxcxmall.com/book/book-test2.png',
                bookName: '风格练习',
                author: '【法】雷蒙啥啥啥'
            },
            {
                image: 'https://img.zhxcxmall.com/book/book-test2.png',
                bookName: '风格练习',
                author: '【法】雷蒙啥啥啥'
            },
            {
                image: 'https://img.zhxcxmall.com/book/book-test2.png',
                bookName: '风格练习',
                author: '【法】雷蒙啥啥啥'
            },
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.getSystemInfo({
            success: res => {
                //获取屏幕的宽度并保存
                this.setData({
                    scrollWidth: res.windowWidth
                });
            }
        });
        var num = 3//每个子数组里的元素个数
        var Arr = new Array(Math.ceil(this.data.recommended.length / num))
        for (var i = 0; i < Arr.length; i++) {
            Arr[i] = new Array();
            for (var j = 0; j < num; j++) {
                Arr[i][j] = '';
            }
        }
        for (var i = 0; i < this.data.recommended.length; i++) {
            Arr[parseInt(i / num)][i % num] = this.data.recommended[i];
        }
        this.setData({
            Arr
        })
    },
    //等比缩放图片并保存
    imageLoad: function (e) {
        //获取图片真实宽度  
        var imgwidth = e.detail.width,
            imgheight = e.detail.height,
            //宽高比  
            ratio = imgwidth / imgheight;
        //console.log(imgwidth, imgheight);
        //计算的高度值  

        var viewHeight = parseInt(this.data.scrollWidth) / ratio;
        var imgheight = viewHeight.toFixed(0);
        var imgheightarray = this.data.imgheights;
        //把每一张图片的高度记录到数组里
        imgheightarray.push(imgheight);

        this.setData({
            imgheights: imgheightarray,
        });
    },
    swiperChange: function (e) {
        //console.log(e.detail.current);    
        this.setData({
            currentNavtab: e.detail.current
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})